今天繼續來介紹 Nmap,今天的內容會圍繞在 NSE ( Nmap Script Engine ) 上,會簡單介紹一下這個功能是什麼用途及怎麼做使用。
NSE 直接翻譯的話叫做 Nmap 腳本引擎, 腳本是指用比較簡短的指令來自動化原本需要手動一步一步的程序,而 Nmap 的腳本引擎就是指用腳本來把流程給簡化,變得原本可能要做很多手動打指令步驟的掃瞄簡化為只要執行一個腳本就能自動完成上面的這些事。
NSE 除了內建的腳本以外也允許使用者可以自行撰寫自己需要的腳本來實現各種自動化的掃瞄任務 ( 自己寫的話要用 Lua 這個腳本語言來實作 ) 。
Nmap 內建的腳本可以在 /usr/share/nmap/scipts 目錄下找到 ( Linux ) ,我目前裝的 7.95 版中有 610 個腳本,可以說是非常的多,我自己也還沒有研究太多,只知道這個功能可以做到很多不同的事,例如 : 基本探測 . 漏洞檢測 . 模糊測試等等,甚至連漏洞利用都辦得到,不得不讚嘆 Nmap 與其開發者們。
/usr/share/nmap/scipts 目錄下的腳本 ( 方便呈現只截一些,7.95 版中總共有 610 個 ) :
├── acarsd-info.nse
├── address-info.nse
├── afp-brute.nse
.
.
.
├── wsdd-discover.nse
├── x11-access.nse
├── xdmcp-discover.nse
├── xmlrpc-methods.nse
├── xmpp-brute.nse
└── xmpp-info.nse
下面的章節會介紹幾個我試用後覺得還不錯用的幾個腳本推薦給讀者。
基本語法 :
nmap [IP位址] --script=[腳本名稱] -p [Port]
註 : 有些腳本會需要加上 Port 方便作使用。
-sC預設腳本比較傾向於單純且快速的探測,而不是做侵入性或其他特殊用途 ( 關於預設腳本的更多說明放在補充的章節裡面 ),預設腳本會列出一些在探測過程找到的一些有用資訊,像是下面實例中的 FTP,就有寫著連線都是用明文傳輸或連線過多久會自動斷線等等,會根據服務的不同寫上一些關於這個服務的情報。
指令 :
nmap [IP位址] -sC
實例 :
這邊是我平常練習 ( LAB 或 CTF ) 的時候會用的指令 -sSVC,實務上可能分開先掃出有總共哪些 open 的 Port 再跑後面的 Service Scan 和預設腳本會比較好一點。
註 : 帶有同樣前綴的指令可以寫在一起
-sSVC意思等同於-sS -sV -sC。
nmap 192.168.31.131 -sSVC -p 21
Starting Nmap 7.95 ( https://nmap.org ) at 2026-09-25 10:23 EDT
Nmap scan report for 192.168.31.131
Host is up (0.00038s latency).
PORT STATE SERVICE VERSION
21/tcp open ftp vsftpd 2.3.4
|_ftp-anon: Anonymous FTP login allowed (FTP code 230)
| ftp-syst:
| STAT:
| FTP server status:
| Connected to 192.168.31.129
| Logged in as ftp
| TYPE: ASCII
| No session bandwidth limit
| Session timeout in seconds is 300
| Control connection is plain text
| Data connections will be plain text
| vsFTPd 2.3.4 - secure, fast, stable
|_End of status
MAC Address: 00:0C:29:37:BF:EF (VMware)
Service Info: OS: Unix
Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 5.50 seconds
safe對目標執行無破壞行為的探測,跟預設腳本類似但預設腳本定位為快速且安全,相較預設腳本會多花不少時間來嘗試更多腳本做探測,會使用的原因是想找出更多資訊但又不想影響到目標的運作。
nmap 192.168.31.131 --script=safe -p 21
Starting Nmap 7.95 ( https://nmap.org ) at 2026-09-25 10:07 EDT
No profinet devices in the subnet
Pre-scan script results:
|_hostmap-robtex: *TEMPORARILY DISABLED* due to changes in Robtex's API. See https://www.robtex.com/api/
| targets-asn:
|_ targets-asn.asn is a mandatory parameter
|_http-robtex-shared-ns: *TEMPORARILY DISABLED* due to changes in Robtex's API. See https://www.robtex.com/api/
| broadcast-dhcp-discover:
| Response 1 of 1:
| Interface: eth0
| IP Offered: 192.168.31.133
| Server Identifier: 192.168.31.254
| Subnet Mask: 255.255.255.0
| Router: 192.168.31.2
| Domain Name Server: 192.168.31.2
| Domain Name: localdomain
| Broadcast Address: 192.168.31.255
|_ NetBIOS Name Server: 192.168.31.2
| broadcast-netbios-master-browser:
|_ip server domain
| broadcast-ping:
| IP: 192.168.31.2 MAC: 00:50:56:f3:35:e0
|_ Use --script-args=newtargets to add the results as targets
| broadcast-listener:
| ether
| ARP Request
| sender ip sender mac target ip
| 192.168.31.2 00:50:56:f3:35:e0 192.168.31.133
| 192.168.31.1 00:50:56:c0:00:08 192.168.31.2
| udp
| DHCP
| srv ip cli ip mask gw dns vendor
| 192.168.31.254 192.168.31.132 255.255.255.0 192.168.31.2 192.168.31.2 -
|_ 192.168.31.254 192.168.31.133 255.255.255.0 192.168.31.2 192.168.31.2 -
| broadcast-igmp-discovery:
| 192.168.31.1
| Interface: eth0
| Version: 2
| Group: 224.0.0.251
| Description: mDNS (rfc6762)
| 192.168.31.1
| Interface: eth0
| Version: 2
| Group: 224.0.0.252
| Description: Link-local Multicast Name Resolution (rfc4795)
| 192.168.31.1
| Interface: eth0
| Version: 2
| Group: 239.255.255.250
| Description: Organization-Local Scope (rfc2365)
|_ Use the newtargets script-arg to add the results as targets
|_multicast-profinet-discovery: 0
|_eap-info: please specify an interface with -e
Nmap scan report for 192.168.31.131
Host is up (0.00044s latency).
PORT STATE SERVICE
21/tcp open ftp
| ftp-syst:
| STAT:
| FTP server status:
| Connected to 192.168.31.129
| Logged in as ftp
| TYPE: ASCII
| No session bandwidth limit
| Session timeout in seconds is 300
| Control connection is plain text
| Data connections will be plain text
| vsFTPd 2.3.4 - secure, fast, stable
|_End of status
|_banner: 220 (vsFTPd 2.3.4)
|_ftp-anon: Anonymous FTP login allowed (FTP code 230)
MAC Address: 00:0C:29:37:BF:EF (VMware)
Host script results:
| dns-blacklist:
| SPAM
| l2.apews.org - FAIL
|_ list.quorum.to - SPAM
| port-states:
| tcp:
|_ open: 21
|_path-mtu: PMTU == 1500
|_fcrdns: FAIL (No PTR record)
| unusual-port:
|_ WARNING: this script depends on Nmap's service/version detection (-sV)
|_ipidseq: All zeros
Post-scan script results:
| reverse-index:
|_ 21/tcp: 192.168.31.131
Nmap done: 1 IP address (1 host up) scanned in 59.59 seconds
vuln漏洞探測就有點類似 Day 8 提到的 searchsploit,會用來找到已知的漏洞,通常有找到漏洞才會有輸出,會輸出一些關於漏洞的詳細如 : CVE編號 . 漏洞利用後可以做到的事物等等,我的話通常會從不同的管道來找公開漏洞而不會單純只有從這邊來看。
nmap 192.168.31.131 --script=vuln -p 21
Starting Nmap 7.95 ( https://nmap.org ) at 2026-09-25 10:01 EDT
Nmap scan report for 192.168.31.131
Host is up (0.00036s latency).
PORT STATE SERVICE
21/tcp open ftp
| ftp-vsftpd-backdoor:
| VULNERABLE:
| vsFTPd version 2.3.4 backdoor
| State: VULNERABLE (Exploitable)
| IDs: BID:48539 CVE:CVE-2011-2523
| vsFTPd version 2.3.4 backdoor, this was reported on 2011-07-04.
| Disclosure date: 2011-07-03
| Exploit results:
| Shell command: id
| Results: uid=0(root) gid=0(root)
| References:
| http://scarybeastsecurity.blogspot.com/2011/07/alert-vsftpd-download-backdoored.html
| https://github.com/rapid7/metasploit-framework/blob/master/modules/exploits/unix/ftp/vsftpd_234_backdoor.rb
| https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2011-2523
|_ https://www.securityfocus.com/bid/48539
MAC Address: 00:0C:29:37:BF:EF (VMware)
Nmap done: 1 IP address (1 host up) scanned in 11.33 seconds
在電腦領域, 腳本是一組相對較短且簡單的指令,通常用於自動化原本需要手動完成的過程。
來源為維基百科,網址放在文章最下面的參考資料。
預設腳本不是單指一個特定腳本,而是經過 Nmap 官方評估過後的腳本集,Nmap 官方會由以下這些要點來做評估。
今天淺淺的介紹了一點 NSE 的內容,到這邊 Nmap 的介紹也差不多告一個段落,明天會補充一些 Nmap 好用的其他選項也分享一下我常用的 Nmap 的指令。
不知不覺鐵人賽也過去一半,每天寫文章跟看資料的生活雖然蠻累的,不過也算是另類的養成一種習慣,現在每天已經都習慣去看一些文件跟文章,希望可以撐下去把30天給跑完,那就明天見啦!